package game.module.apyment.processor;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.HallServer;
import game.common.PlayingRoleMsgProcessor;
import game.entity.PlayingRole;
import game.module.payment.logic.PaymentManager;
import lion.common.MsgCodeAnn;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lua.LuaMessageHall.C2SPayPreOrder;

@MsgCodeAnn(msgcode = C2SPayPreOrder.id, accessLimit = 500)
public class PayPreOrderProcessor extends PlayingRoleMsgProcessor {

	private static Logger logger = LoggerFactory.getLogger(PayPreOrderProcessor.class);

	@Override
	public void process(final PlayingRole hero, RequestMessageRaw request) throws Exception {
		C2SPayPreOrder reqMsg = C2SPayPreOrder.parse(request);
		final int playerId = hero.getId();
		logger.info("swiftpass pre order,playeyId={},shopId={}", playerId, reqMsg.shop_id);
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PaymentManager.getInstance().preOrderPay(hero, reqMsg.shop_id);
			}
		});
	}

	@Override
	public void processProto(PlayingRole playingRole, RequestProtoMessage request) throws Exception {
		// null
	}

	@Override
	public void processWebsocket(PlayingRole playingRole, MyRequestMessage request) throws Exception {
		// null
	}

	public static void main(String[] args) {
		String clientIp = "/192.168.0.200:34302";
		if (clientIp.startsWith("/")) {
			clientIp = clientIp.substring(1);
		}
		if (clientIp.indexOf(":") > -1) {
			clientIp = clientIp.substring(0, clientIp.indexOf(":"));
		}
		System.out.println(clientIp);
	}

}
